/*!
 * \file t3_core.h
 *
 * \brief weblogic t3数据包解析
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 2.0
 * \author wuwk
 * \date 2015/11/20
 *
 */

#ifndef __T3_CORE_H_
#define __T3_CORE_H_

#include "conntrack.h"
#include "module.h"
#include "frreport_comm.h"
#include "frbyte_buffer.h"

#define T3_NO                       0
#define T3_YES                      1

#define T3_REQUEST                  0
#define T3_RESPONSE                 1

#define T3_PTOP                     0
//#define T3_PUB                    1
#define T3_SUB                      2
#define T3_NOTIFY                   3

union int32_float_bits {
    int32_t int_bits;
    float float_bits;
};

union int64_double_bits {
    int64_t int_bits;
    double double_bits;
};

/*! 分片包数据 */
typedef struct __st_L7_fragment_t3 {
    uint32_t u32_total_len;                 // 实际数据总长度
    uint32_t u32_left_len;                  // 还需要接收的数据长度
    Frbyte_Packet *p_st_data;               // packet数据
} L7_fragment_t3;

typedef struct __st_protocol_info_t3 {
    char *p_version;
    unsigned int ui_version_len;
} Protocol_info_t3;

/* session信息 */
typedef struct __st_L7_session_t3 {
    char * p_server;                        // 服务名,版本号
    char *p_queue;                          // 队列名
    char *p_title;                          // title
    char *p_ejbname;
    char *p_weblogic_server;
    char *p_jms_server;
    char *p_jms_module;
} L7Session_t3;

/*! t3 私有信息储存 */
typedef struct __L7session_t3_private
{
    unsigned long ul_seq;
    unsigned int ui_responseid;    //响应码
    int is_login;                             //t3协议已识别
    int i_status;                             //t3协议判断用
    int is_topic;                             //主题
    int i_type;                               //SUB/NOTIFY
    int i_methodid;                           //JAVA方法
    int i_responserequired;                   //是否需要响应
    int i_browse_status;                      //浏览消息
    int is_ejb;
    L7_fragment_t3 *p_st_fragment;            //分片包数据
    Protocol_info_t3 *p_st_protocol_info;     //t3协议信息
    L7Session_t3 *p_st_session;               //session
    L4_transaction st_l4_trans;
    Frlist_header *p_lst_req;                 //数据  req
    Frlist_header *p_lst_mq;                  //数据  mq
    Frreport_body_data *p_st_body_data_req;
    Frreport_body_data *p_st_body_data_resp;
} L7session_t3_private;

int t3_detect(Conntrack *p_st_conn, Apm_packet *p_st_packet);

int t3_analysis(Conntrack *p_st_conn
                  , Apm_packet *p_st_packet
                  , Frhash_header *p_st_hash_report);

int t3_session_destroy(void *p_private_session);

#endif
